<%@page import="org.json.simple.JSONArray"%>
<%@page import="vo.StudyVo"%>
<%@page import="java.util.List"%>
<%@page import="dao.StudyDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
	String menu_no = request.getParameter("menu_no");
	String cateNo = request.getParameter("cate_no");
	String state = request.getParameter("state");
	String new_name = request.getParameter("cate_name");
	
	System.out.println("menu_no:"+menu_no);
	System.out.println("cate_no:"+cateNo);
	System.out.println("state:"+state);
	
	
	
	StudyDao dao =StudyDao.getDao();
	List<StudyVo> list = null;

	if(cateNo!=null && state!=null){//swap처리
		int cate_no = Integer.parseInt(cateNo);
		int cate_step = dao.cateStep(cate_no);
		
		if(state.equals("up")){
			System.out.println("up");
			dao.stepDown(cate_step-1);
			dao.categoryUp(cate_no);
		
		}else if(state.equals("down")){
			System.out.println("down");
			dao.stepUp(cate_step+1);
			dao.categoryDown(cate_no);

		}else if(state.equals("rename")){
			StudyVo svo = new StudyVo();
			svo.setCate_no(cate_no);
			svo.setCate_name(new_name);
			dao.cateRename(svo);
			
		}else if(state.equals("delete")){
			/* dao.deleteCategorySubject(cate_no);
			dao.deleteCategoryTitle(cate_no);
			dao.deleteCategory(cate_no); */
		}
		
	}
	
	list = dao.selectCategory(Integer.parseInt(menu_no));
	
	JSONArray jarr = new JSONArray();
	jarr.addAll(list);
	out.println(jarr.toString());
%>